﻿using DGIS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace DGIS.Control
{
    public class DownloadControl
    {
        DGIS.GscloudService.IService.IDownloadService downloadService = new DGIS.GscloudService.Service.DownloadService();

        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="item"></param>
        /// <param name="isResume">是否续传</param>
        /// <param name="download">是否马上下载</param>
        /// <returns></returns>
        public bool Download(DownloadFile item,bool isResume,bool download,Func<string,int,int> callback)
        {
            return downloadService.AddDownloadFile(item, isResume, download, callback);
        }

        /// <summary>
        /// 停止下载任务
        /// </summary>
        /// <param name="intPtr"></param>
        /// <returns></returns>
        public bool Stop(IntPtr intPtr)
        {
            return downloadService.StopDownload(intPtr);
        }

        /// <summary>
        /// 继续下载任务
        /// </summary>
        /// <param name="intPtr"></param>
        /// <returns></returns>
        public bool Start(IntPtr intPtr)
        {
            return downloadService.StartDownload(intPtr);
        }

        /// <summary>
        /// 删除任务记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DelCompleteFile(string id)
        {
            return downloadService.DelRecord(id);
        }

        /// <summary>
        /// 删除下载任务
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Del(DownloadFile item)
        {
            return downloadService.DelDownload(item);
        }        

        /// <summary>
        /// 获取未完成任务
        /// </summary>
        /// <returns></returns>
        public List<DownloadFile> GetResumeTasks()
        {
            return downloadService.GetResumeDownloadFiles();
        }

        /// <summary>
        /// 获取已经完成任务
        /// </summary>
        /// <returns></returns>
        public List<DownloadFile> GetCompleteTasks()
        {
            return downloadService.GetCompleteDownloadFiles();
        }
    }
}
